
#ifndef OPERATION_H
#define OPERATION_H

#include <BSet>
#include <BHandler>
#include <BScrollArea>
#include <BPixmap>

#include "ImageLayer.h"

typedef BSet<BWidget*>	BWidgetSet;

class PixmapArea;
class Operation : public BObject
{
	friend class PixmapArea;
public:
	Operation(const BString& name);
	~Operation();

	bool setPixmapArea(PixmapArea* pixmapArea);
	PixmapArea* pixmapArea() const;
	BPixmap* pixmap();

	void setParent(Operation* parent);
	const Operation* parent() const;
	Operation* parent();

	void addChild(Operation* child);
	void removeChild(Operation* child);
	void clearChildren();

	int childCount() const;
	Operation* child(int index) const;
	Operation* child(const BString& name) const;

	bool contains(Operation* child);
	bool contains(const BString& name) const;

	bool detach();
	bool fresh() const;

protected:
	virtual void attached(BWidget* widget);
	virtual void detached(BWidget* widget);

	virtual bool event(const BEvent& event);
	virtual void paint(BPainter& painter);
	virtual void update(double time);

	virtual void freshEvent(const BEvent& event);
	virtual bool moveEvent(const BEvent& event);
	virtual bool resizeEvent(const BEvent& event);

	virtual bool focusEvent(const BEvent& event);
	virtual bool keyDownEvent(const BKeyEvent& keyEvent);
	virtual bool keyUpEvent(const BKeyEvent& keyEvent);

	virtual bool mouseEnterEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseLeaveEvent(const BMouseEvent& mouseEvent);
	virtual bool mousePressEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseMoveEvent(const BMouseEvent& mouseEvent);

	virtual bool mouseWheelEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseClickEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseDoubleClickEvent(const BMouseEvent& mouseEvent);

	virtual bool dragEnterEvent(const BDragEvent& dragEvent);
	virtual bool dragLeaveEvent(const BDragEvent& dragEvent);
	virtual bool dragMoveEvent(const BDragEvent& dragEvent);
	virtual bool dragDropEvent(const BDragEvent& dragEvent);

private:
	PixmapArea*		_pixmapArea;
	Operation*		_parent;
	BArray<BHolder<Operation>>	_children;

};

#endif
